package nkr1pt.popkorn.schedule.jobs;

import com.google.inject.Inject;
import java.lang.Exception;
import nkr1pt.popkorn.download.DownloadManager;
import nkr1pt.popkorn.exceptions.ExceptionHandler;
import nkr1pt.popkorn.exceptions.RecoverableException;
import nkr1pt.popkorn.schedule.triggers.ImmediateTrigger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 * Quartz job to download files in downloadable state.
 *
 * @author Kristof Vanhaeren
 */
public class DownloadJob implements Job {

    private DownloadManager downloadManager;

    private ExceptionHandler exceptionHandler;

    public DownloadJob() {
        exceptionHandler = new ExceptionHandler();
    }

    @Inject
    public void setDownloadManager(DownloadManager downloadManager) {
        this.downloadManager = downloadManager;
    }


    public void execute(JobExecutionContext context) {
        try {
           downloadManager.startDownloading();
        } catch (Throwable t) {
           exceptionHandler.handleException(t);
        }
        
    }

}